package com.ruoyi.womp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.womp.domain.WompHandlingOpinions;
import com.ruoyi.womp.service.IWompHandlingOpinionsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 意见建议库Controller
 * 
 * @author mzz
 * @date 2022-04-11
 */
@Controller
@RequestMapping("/womp/handlingOpinions")
public class WompHandlingOpinionsController extends BaseController
{
    private String prefix = "womp/handlingOpinions";

    @Autowired
    private IWompHandlingOpinionsService wompHandlingOpinionsService;

    @RequiresPermissions("womp:handlingOpinions:view")
    @GetMapping()
    public String handlingOpinions()
    {
        return prefix + "/handlingOpinions";
    }

    /**
     * 查询意见建议库列表
     */
    @RequiresPermissions("womp:handlingOpinions:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WompHandlingOpinions wompHandlingOpinions)
    {
        startPage();
        List<WompHandlingOpinions> list = wompHandlingOpinionsService.selectWompHandlingOpinionsList(wompHandlingOpinions);
        return getDataTable(list);
    }

    /**
     * 导出意见建议库列表
     */
    @RequiresPermissions("womp:handlingOpinions:export")
    @Log(title = "意见建议库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WompHandlingOpinions wompHandlingOpinions)
    {
        List<WompHandlingOpinions> list = wompHandlingOpinionsService.selectWompHandlingOpinionsList(wompHandlingOpinions);
        ExcelUtil<WompHandlingOpinions> util = new ExcelUtil<WompHandlingOpinions>(WompHandlingOpinions.class);
        return util.exportExcel(list, "意见建议库数据");
    }

    /**
     * 新增意见建议库
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存意见建议库
     */
    @RequiresPermissions("womp:handlingOpinions:add")
    @Log(title = "意见建议库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WompHandlingOpinions wompHandlingOpinions)
    {
        return toAjax(wompHandlingOpinionsService.insertWompHandlingOpinions(wompHandlingOpinions));
    }

    /**
     * 修改意见建议库
     */
    @RequiresPermissions("womp:handlingOpinions:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WompHandlingOpinions wompHandlingOpinions = wompHandlingOpinionsService.selectWompHandlingOpinionsById(id);
        mmap.put("wompHandlingOpinions", wompHandlingOpinions);
        return prefix + "/edit";
    }

    /**
     * 修改保存意见建议库
     */
    @RequiresPermissions("womp:handlingOpinions:edit")
    @Log(title = "意见建议库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WompHandlingOpinions wompHandlingOpinions)
    {
        return toAjax(wompHandlingOpinionsService.updateWompHandlingOpinions(wompHandlingOpinions));
    }

    /**
     * 删除意见建议库
     */
    @RequiresPermissions("womp:handlingOpinions:remove")
    @Log(title = "意见建议库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wompHandlingOpinionsService.deleteWompHandlingOpinionsByIds(ids));
    }
}
